package priv.mill.yuanxing;

import java.util.Date;


public class Main {


	public static void main(String[] args) throws CloneNotSupportedException, InterruptedException {
		Person person = new Person();
		person.setAge(18);
		person.setName("张三");
		person.setDate(new Date());
		System.out.println(person.getDate());
		
		Thread.sleep(2000);
		Person p2=(Person) person.clone();
		p2.setAge(28);
		p2.getDate().setTime((new Date()).getTime());
		
		System.out.println(person.getDate());
		
//		System.out.println(p2.getDate()==person.getDate());
		
		
	} 
}
/**
 * 浅克隆
 * @author mill
 * @date 2018年1月8日
 * Person
 */
class Person implements Cloneable{
	private int age;
	private String name;
	private Date date;
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Person [age=" + age + ", name=" + name + "]";
	}
	
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	@Override
	public Object clone() throws CloneNotSupportedException {
		 Object clone = super.clone();
		 Person p1=(Person) clone;
		 Date clone2 = (Date) p1.getDate().clone();
		 p1.setDate(clone2);
		 return clone;
	}
}
